use serde::{Serialize, Deserialize};

/// 宏观经济指标
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MacroEconomicIndicators {
    pub gdp: f64,                // 国内生产总值
    pub gdp_growth: f64,         // GDP增长率
    pub inflation: f64,          // 通货膨胀率
    pub unemployment: f64,       // 失业率
    pub interest_rate: f64,      // 基准利率
    pub consumer_confidence: f64,// 消费者信心指数
    pub trade_balance: f64,      // 贸易差额
    pub fiscal_deficit: f64,     // 财政赤字率
}

impl Default for MacroEconomicIndicators {
    fn default() -> Self {
        MacroEconomicIndicators {
            gdp: 1_000_000.0,    // 基准值
            gdp_growth: 0.03,
            inflation: 0.02,
            unemployment: 0.05,
            interest_rate: 0.03,
            consumer_confidence: 100.0,
            trade_balance: 0.0,
            fiscal_deficit: 0.03,
        }
    }
}

impl MacroEconomicIndicators {
    /// 更新指标基于政策影响
    pub fn update(&mut self, impact: &PolicyImpact) {
        // GDP影响
        self.gdp *= 1.0 + impact.gdp_effect;
        self.gdp_growth += impact.growth_effect;
        
        // 通胀影响
        self.inflation += impact.inflation_effect;
        self.inflation = self.inflation.max(0.0);
        
        // 就业影响
        self.unemployment += impact.employment_effect;
        self.unemployment = self.unemployment.clamp(0.01, 0.25);
        
        // 利率调整
        self.interest_rate += impact.interest_rate_effect;
        
        // 消费者信心
        self.consumer_confidence += impact.consumer_confidence_effect;
        
        // 贸易平衡
        self.trade_balance += impact.trade_balance_effect;
        
        // 财政赤字
        self.fiscal_deficit += impact.fiscal_effect;
    }

    /// 计算经济健康指数 (0-100)
    pub fn health_index(&self) -> f64 {
        let mut index = 100.0;
        
        // GDP增长因素
        index += self.gdp_growth * 100.0;
        
        // 通胀惩罚
        index -= self.inflation.abs() * 50.0;
        
        // 失业率惩罚
        index -= self.unemployment * 30.0;
        
        // 消费者信心加成
        index += (self.consumer_confidence - 100.0) * 0.5;
        
        // 贸易平衡影响
        index += self.trade_balance / self.gdp * 1000.0;
        
        // 财政健康
        index -= self.fiscal_deficit * 300.0;
        
        index.clamp(0.0, 200.0)
    }
}